package com.group.three.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.three.mapper.PersonMapper;
import com.group.three.pojo.Person;
import com.group.three.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonMapper personMapper;

    @Override
    public int register(Long personId, String personName, String personEmail, String personPhone, String personPassword, Integer role, LocalDateTime now) {
        return personMapper.register(personId,personName,personEmail,personPhone,personPassword,role,now);
    }

    @Override
    public Person selectPersonByNameOrEmailOrPhone(String personName,Integer role) {
        return personMapper.selectPersonByNameOrEmailOrPhone( personName,role);
    }

    @Override
    public int updatePerson(Long personId, String personName, String personEmail, String personPhone,String introduction) {
        return personMapper.updatePerson(personId,personName,personEmail,personPhone,introduction);
    }

    @Override
    public int updatePassword(String newPassword, Long personId) {
        return personMapper.updatePassword(newPassword,personId);
    }

    @Override
    public PageInfo<Person> selectListByRole(int page, int size, Integer role) {
        PageHelper.startPage(page,size);
        List<Person> people = personMapper.selectListByRole(role);
        PageInfo<Person> pageInfo=new PageInfo<>(people,page);
        return pageInfo;
    }

    @Override
    public int updateStatusByPersonId(Long personId, Integer status) {
        return personMapper.updateStatusByPersonId(personId,status);
    }

    @Override
    public int updateImage(String personImage, Long personId) {
        return personMapper.updateImage(personImage,personId);
    }

    @Override
    public int insertAdminRole(Long personId, String personName, String personPassword, Integer role, Integer status) {
        return personMapper.insertAdminRole(personId,personName,personPassword,role,status);
    }

    @Override
    public PageInfo<Person> selectInformByLikeName(int page, int size, String name,Integer role) {
        PageHelper.startPage(page,size);
        List<Person> people = personMapper.selectInformByLikeName(name, role);
        PageInfo<Person> pageInfo = new PageInfo<>(people, page);
        return pageInfo;
    }

    @Override
    public PageInfo<Person> selectInformByLikeNameNotRole(int page, int size, String name,Integer role) {
        PageHelper.startPage(page,size);
        List<Person> people = personMapper.selectInformByLikeNameNotRole(name, role);
        PageInfo<Person> pageInfo = new PageInfo<>(people, page);
        return pageInfo;
    }

    @Override
    public PageInfo<Person> selectLogsByRole(int page, int size, Integer role,String name) {
        PageHelper.startPage(page,size);
        List<Person> people = personMapper.selectLogsByRole(role,name);
        PageInfo<Person> pageInfo = new PageInfo<>(people, page);
        return pageInfo;
    }

    @Override
    public PageInfo<Person> selectLogsByNotRole(int page, int size, Integer role,String name) {
        PageHelper.startPage(page,size);
        List<Person> people = personMapper.selectLogsByNotRole(role,name);
        PageInfo<Person> pageInfo = new PageInfo<>(people, page);
        return pageInfo;
    }
    @Override
    public PageInfo<Person> selectListByNotRole(int page, int size, Integer role) {
        PageHelper.startPage(page,size);
        List<Person> people = personMapper.selectListByNotRole(role);
        PageInfo<Person> pageInfo=new PageInfo<>(people,page);
        return pageInfo;
    }

    @Override
    public Person selectInformById(Long personId) {
        return personMapper.selectInformById(personId);
    }
}
